package demo.test;

import org.apache.commons.lang.StringUtils;

public class EmojiFilterUtils {

    /**
     * 将emoji表情替换成*
     * 
     * @param source
     * @return 过滤后的字符串
     */
    public static String filterEmoji(String source) {
        if(StringUtils.isNotBlank(source)){
            return source.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", "");
        }else{
            return source;
        }
    }
    public static void main(String[] arg ){
        try{
            String text = "和邻居一起买的，今天终于安装好了，师傅真心不错，很专业，那么小的空间都能装进去，设计的很好\uD83D\uDC4D 终于用上干净的水啦，喝起来甜甜的，口感不错";
            System.out.println(text);
            System.out.println(text.length());
            System.out.println(text.replaceAll("[\\ud83c\\udc00-\\ud83c\\udfff]|[\\ud83d\\udc00-\\ud83d\\udfff]|[\\u2600-\\u27ff]", "*"));
            System.out.println(filterEmoji(text));
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}